package polymorphic;

/**
 * @Package: polymorphic
 * @ClassName: PolymorphicParameter
 * @Author: x2606
 * @CreateTime: 2022/2/27 21:54
 * @Description: 多态参数
 */

public class PolymorphicParameter {
    public static void main(String[] args) {
        Sun sun = new Sun("jack",30);
        hello(sun);
    }
    //使用父类做形参，接收子类实参
    public static void hello(Fa fa){
        fa.say();
    }
}

class Fa{
    private String name;
    private int age;

    public Fa(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void say(){
        System.out.println(getName()+" father");
    }
}

class Sun extends Fa {
    private String name;
    private int age;

    public Sun(String name,int age) {
        super(name, age);
        this.name = name;
        this.age = age;
    }

    @Override
    public void say() {
        System.out.println(getName()+" sun");
    }
}